﻿// Decompiled by AS3 Sorcerer 6.12
// www.as3sorcerer.com

//Link

package 
{
    import flash.display.Sprite;
    import flash.media.SoundChannel;
    import flash.events.Event;

    public class Link extends Sprite 
    {

        private const _SafeStr_202:Number = 0.5;
        private const _SafeStr_203:Number = 5;
        private const _SafeStr_208:Number = 0.4;
        private const _SafeStr_227:Number = 0.2;

        private var m_game:Level;
        private var _SafeStr_201:SoundChannel = null;
        private var _SafeStr_204:Anchor = null;
        private var _SafeStr_217:Anchor = null;
        private var _SafeStr_219:int = 0;
        private var _SafeStr_215:Number = 0;
        private var _SafeStr_209:Number;
        private var _SafeStr_223:Boolean = true;
        private var _SafeStr_211:Number;
        private var _SafeStr_197:Boolean = false;
        private var _SafeStr_229:Sync = null;
        private var _SafeStr_210:Number;
        private var _SafeStr_207:Number;
        private var _SafeStr_218:Cell = null;
        private var _SafeStr_222:int;
        private var _SafeStr_97:Boolean = false;
        private var _SafeStr_213:Anchor;
        private var _SafeStr_226:Anchor;
        private var _SafeStr_123:Number;
        private var _SafeStr_216:Number = 0;
        private var _SafeStr_125:Number;
        private var _SafeStr_196:Cell = null;
        private var _SafeStr_214:Array;
        private var _SafeStr_221:int = -1;
        private var _SafeStr_198:Link = null;
        private var _SafeStr_195:Boolean = false;
        private var _SafeStr_200:int;
        private var _SafeStr_124:Number;
        private var _SafeStr_122:Number;
        private var _SafeStr_228:LinkSegment;
        private var _SafeStr_199:Number;

        public function Link(game:Level, orig:Cell, dest:Cell)
        {
            this.m_game = game;
            this._SafeStr_196 = orig;
            this._SafeStr_218 = dest;
            this._SafeStr_209 = 0;
            this._SafeStr_228 = null;
            this._SafeStr_211 = 0;
            this._SafeStr_214 = new Array();
            this._SafeStr_229 = new Sync(0.5);
            var a1:Anchor = orig.getAnchorTo(dest);
            var a2:Anchor = dest.getAnchorTo(orig);
            this._SafeStr_213 = a1;
            this._SafeStr_226 = a2;
            a1.addListener(this._SafeStr_194);
            a2.addListener(this._SafeStr_194);
            this._SafeStr_114(a1.x, a1.y, a2.x, a2.y);
            orig.addOriginLink(this);
            orig.addImpulse((orig.getAngleTo(dest) + 180), 1);
            this._SafeStr_201 = SoundMgr.playSfx(SoundMgr.TENTACLE_GROW);
            addEventListener(Event.ENTER_FRAME, this.onEnterFrame);
        }

        public static function getRequiredPower(len:Number):int
        {
            return (len / (LinkSegment.INTERVAL + LinkSegment.SIZE));
        }


        public function cutAtPoint(x:Number, y:Number):void
        {
            var dist:Number;
            if (this._SafeStr_195)
            {
                return;
            };
            this._SafeStr_196.delOriginLink(this);
            this._SafeStr_195 = true;
            if (((this._SafeStr_197) && (!(this._SafeStr_198))))
            {
                dist = this._SafeStr_205(this._SafeStr_125, this._SafeStr_124, x, y);
                this._SafeStr_221 = Math.round((dist / this._SafeStr_199));
            }
            else
            {
                this._SafeStr_221 = this._SafeStr_200;
            };
            this._SafeStr_197 = false;
            if (this._SafeStr_198)
            {
                this._SafeStr_198.setSplitLink(null);
                this.setSplitLink(null);
            };
            SoundMgr.stopSfx(this._SafeStr_201);
            this._SafeStr_201 = null;
            SoundMgr.playSfx(SoundMgr.TENTACLE_CUT);
        }

        private function _SafeStr_205(x1:Number, y1:Number, x2:Number, y2:Number):Number
        {
            var dx:Number = (x2 - x1);
            var dy:Number = (y2 - y1);
            return (Math.sqrt(((dx * dx) + (dy * dy))));
        }

        private function _SafeStr_206(seg:LinkSegment, pos:int, prevX:Number=-1, prevY:Number=-1, reversePos:Boolean=false):void
        {
            var dispAng:Number = (this._SafeStr_207 + (Math.PI / 2));
            var fadePos:int = int(((pos < (this._SafeStr_200 / 2)) ? pos : (this._SafeStr_200 - pos)));
            var dispFade:Number = (fadePos * this._SafeStr_208);
            if (dispFade > 1)
            {
                dispFade = 1;
            };
            var offset:Number = this._SafeStr_209;
            var sign:Number = 1;
            if (reversePos)
            {
                offset = (offset + this._SafeStr_210);
                sign = -1;
            };
            var dispValue:Number = ((Math.sin((this._SafeStr_211 + (pos * this._SafeStr_202))) * this._SafeStr_203) * dispFade);
            seg.x = ((this._SafeStr_125 + (Math.cos(this._SafeStr_207) * (((sign * pos) * this._SafeStr_199) + offset))) + (Math.cos(dispAng) * dispValue));
            seg.y = ((this._SafeStr_124 + (Math.sin(this._SafeStr_207) * (((sign * pos) * this._SafeStr_199) + offset))) + (Math.sin(dispAng) * dispValue));
            seg.setTendrilSize((dispFade * 8));
            var dir:Number = this._SafeStr_207;
            if (prevX >= 0)
            {
                dir = Math.atan2((seg.y - prevY), (seg.x - prevX));
            };
            seg.rotation = ((dir * 180) / Math.PI);
        }

        private function _SafeStr_212():void
        {
            var splitLen:Number;
            var dx:Number = (this._SafeStr_204.x - this._SafeStr_213.x);
            var dy:Number = (this._SafeStr_204.y - this._SafeStr_213.y);
            var splitX:Number = 0;
            var splitY:Number = 0;
            if (!this._SafeStr_197)
            {
                splitLen = ((this._SafeStr_214.length * this._SafeStr_199) + this._SafeStr_209);
                splitX = (this._SafeStr_125 + (Math.cos(this._SafeStr_215) * splitLen));
                splitY = (this._SafeStr_124 + (Math.sin(this._SafeStr_215) * splitLen));
            }
            else
            {
                splitX = (this._SafeStr_125 + (dx / 2));
                splitY = (this._SafeStr_124 + (dy / 2));
            };
            if (((splitLen >= (this._SafeStr_216 / 2)) && (!(this._SafeStr_195))))
            {
                this._SafeStr_197 = true;
            };
            this._SafeStr_217.update(splitX, splitY);
        }

        public function cutAt(percent:Number):void
        {
            if (this._SafeStr_195)
            {
                return;
            };
            this._SafeStr_196.delOriginLink(this);
            this._SafeStr_195 = true;
            if (percent < 0)
            {
                percent = 0;
            };
            if (percent > 1)
            {
                percent = 1;
            };
            if (((this._SafeStr_197) && (!(this._SafeStr_198))))
            {
                this._SafeStr_221 = Math.round(((this._SafeStr_210 * percent) / this._SafeStr_199));
            }
            else
            {
                this._SafeStr_221 = this._SafeStr_200;
            };
            this._SafeStr_197 = false;
            if (this._SafeStr_198)
            {
                this._SafeStr_198.setSplitLink(null);
                this.setSplitLink(null);
            };
            SoundMgr.stopSfx(this._SafeStr_201);
            this._SafeStr_201 = null;
        }

        public function getDestCell():Cell
        {
            return (this._SafeStr_218);
        }

        private function _SafeStr_220():void
        {
            var seg:LinkSegment;
            if (((this._SafeStr_195) && (this._SafeStr_214.length > 0)))
            {
                if (this._SafeStr_221 >= 0)
                {
                    seg = this._SafeStr_214.shift();
                    this._SafeStr_230(seg);
                    this._SafeStr_196.receiveAttack(this._SafeStr_196.type, 1);
                    this._SafeStr_221--;
                };
                if ((this._SafeStr_221 + 1) < this._SafeStr_214.length)
                {
                    seg = this._SafeStr_214.pop();
                    this._SafeStr_230(seg);
                    this._SafeStr_218.receiveAttack(this._SafeStr_196.type, 1);
                };
            };
            if (this._SafeStr_214.length == 0)
            {
                this.destruct();
            };
        }

        private function _SafeStr_114(x1:Number, y1:Number, x2:Number, y2:Number):void
        {
            this._SafeStr_125 = x1;
            this._SafeStr_124 = y1;
            this._SafeStr_123 = x2;
            this._SafeStr_122 = y2;
            var dx:Number = (x2 - x1);
            var dy:Number = (y2 - y1);
            this._SafeStr_207 = Math.atan2(dy, dx);
            this._SafeStr_210 = Math.sqrt(((dx * dx) + (dy * dy)));
            this._SafeStr_222 = (this._SafeStr_210 / (LinkSegment.SIZE + LinkSegment.INTERVAL));
            if (this._SafeStr_222 < 5)
            {
                this._SafeStr_222 = (this._SafeStr_222 + 1);
            };
            this._SafeStr_93();
        }

        private function _SafeStr_224():void
        {
            var load:int;
            var color:uint;
            var seg:LinkSegment;
            var i:int = (this._SafeStr_214.length - 1);
            while (i >= 0)
            {
                seg = this._SafeStr_214[i];
                load = seg.load;
                color = seg.baseColor;
                if (load > 0)
                {
                    seg.setLoad(0);
                    if (i < (this._SafeStr_214.length - 1))
                    {
                        seg = this._SafeStr_214[(i + 1)];
                        seg.setLoad(load);
                        seg.baseColor = color;
                    }
                    else
                    {
                        this._SafeStr_218.receiveAttack(this._SafeStr_196.type, load);
                    };
                };
                i--;
            };
        }

        private function _SafeStr_225(anchor:Anchor):void
        {
            this._SafeStr_204 = this._SafeStr_226;
            this._SafeStr_226.removeListener(this._SafeStr_194);
            this._SafeStr_226 = anchor;
            this._SafeStr_226.addListener(this._SafeStr_194);
            this._SafeStr_194(anchor);
        }

        public function destruct():void
        {
            this._SafeStr_213.removeListener(this._SafeStr_194);
            this._SafeStr_226.removeListener(this._SafeStr_194);
            if (!this._SafeStr_97)
            {
                removeEventListener(Event.ENTER_FRAME, this.onEnterFrame);
            };
            this.m_game.delLink(this);
            while (this._SafeStr_214.length > 0)
            {
                this._SafeStr_230(this._SafeStr_214.pop());
            };
        }

        public function get power():int
        {
            return (this._SafeStr_214.length);
        }

        private function onEnterFrame(event:Event):void
        {
            var seg:LinkSegment;
            this._SafeStr_211 = (this._SafeStr_211 + this._SafeStr_227);
            this._SafeStr_219++;
            if (this._SafeStr_219 > 1)
            {
                this._SafeStr_219 = 0;
                this._SafeStr_224();
            };
            if (this._SafeStr_228)
            {
                this._SafeStr_233();
            };
            if (this._SafeStr_217)
            {
                this._SafeStr_212();
            };
            if (((!(this._SafeStr_217)) || (this._SafeStr_197)))
            {
                this._SafeStr_223 = (this._SafeStr_214.length <= this._SafeStr_222);
            };
            if (this._SafeStr_195)
            {
                this._SafeStr_220();
            };
            while (this._SafeStr_214.length > (this._SafeStr_222 + 1))
            {
                seg = this._SafeStr_214.pop();
                this._SafeStr_230(seg);
                this._SafeStr_196.receiveAttack(this._SafeStr_196.type, 1);
                this._SafeStr_200 = this._SafeStr_222;
            };
            this._SafeStr_93();
            this._SafeStr_229.tick();
            if (((((!(this._SafeStr_197)) && (!(this._SafeStr_195))) && (this._SafeStr_214.length >= (this._SafeStr_222 + 1))) && (this._SafeStr_217 == null)))
            {
                this._SafeStr_197 = true;
                this._SafeStr_218.addImpulse(this._SafeStr_196.getAngleTo(this._SafeStr_218));
                SoundMgr.stopSfx(this._SafeStr_201);
                this._SafeStr_201 = null;
                this.m_game.onLinkAttached(this);
            };
        }

        public function getOrigCell():Cell
        {
            return (this._SafeStr_196);
        }

        public function isBusy():Boolean
        {
            return (!(this._SafeStr_228 == null));
        }

        public function isCut():Boolean
        {
            return (this._SafeStr_195);
        }

        private function _SafeStr_230(seg:LinkSegment):void
        {
            removeChild(seg);
            seg.destruct();
            seg = null;
        }

        private function _SafeStr_231():Boolean
        {
            if ((((this._SafeStr_223) && (!(this._SafeStr_195))) && (this._SafeStr_228 == null)))
            {
                this._SafeStr_228 = new LinkSegment(this._SafeStr_229, this._SafeStr_196.baseColor());
                this._SafeStr_228.x = this._SafeStr_125;
                this._SafeStr_228.y = this._SafeStr_124;
                this._SafeStr_228.rotation = ((this._SafeStr_207 * 180) / Math.PI);
                this._SafeStr_228.setSize(0);
                this._SafeStr_209 = 0;
                addChild(this._SafeStr_228);
                return (true);
            };
            return (false);
        }

        private function _SafeStr_232():Anchor
        {
            this._SafeStr_217 = new Anchor(this._SafeStr_213.x, this._SafeStr_213.y);
            this._SafeStr_204 = this._SafeStr_226;
            this._SafeStr_226 = this._SafeStr_217;
            this._SafeStr_226.addListener(this._SafeStr_194);
            this._SafeStr_194(this._SafeStr_217);
            return (this._SafeStr_217);
        }

        private function _SafeStr_194(a:Anchor):void
        {
            var dx:Number;
            var dy:Number;
            this._SafeStr_114(this._SafeStr_213.x, this._SafeStr_213.y, this._SafeStr_226.x, this._SafeStr_226.y);
            if (this._SafeStr_217)
            {
                dx = (this._SafeStr_204.x - this._SafeStr_213.x);
                dy = (this._SafeStr_204.y - this._SafeStr_213.y);
                this._SafeStr_215 = Math.atan2(dy, dx);
                this._SafeStr_216 = Math.sqrt(((dx * dx) + (dy * dy)));
            };
        }

        private function _SafeStr_233():void
        {
            var len:int;
            this._SafeStr_209 = (this._SafeStr_209 + 4);
            var div:Number = (LinkSegment.SIZE / (LinkSegment.SIZE + LinkSegment.INTERVAL));
            this._SafeStr_228.setSize((this._SafeStr_209 * div));
            if (this._SafeStr_209 >= (LinkSegment.SIZE + LinkSegment.INTERVAL))
            {
                this._SafeStr_228.setSize(LinkSegment.SIZE);
                len = this._SafeStr_214.unshift(this._SafeStr_228);
                this._SafeStr_228 = null;
                this._SafeStr_209 = 0;
                this._SafeStr_200 = this._SafeStr_222;
            };
        }

        public function getDestAnchor():Anchor
        {
            return (this._SafeStr_226);
        }

        private function _SafeStr_93():void
        {
            if (this._SafeStr_197)
            {
                this._SafeStr_199 = ((this._SafeStr_210 - this._SafeStr_209) / this._SafeStr_200);
            }
            else
            {
                this._SafeStr_199 = (LinkSegment.SIZE + LinkSegment.INTERVAL);
            };
            var i:int;
            var prevX:Number = -1;
            var prevY:Number = -1;
            var seg:LinkSegment;
            if (!this._SafeStr_195)
            {
                i = 0;
                while (i < this._SafeStr_214.length)
                {
                    seg = this._SafeStr_214[i];
                    this._SafeStr_206(seg, i, prevX, prevY);
                    prevX = seg.x;
                    prevY = seg.y;
                    i++;
                };
            }
            else
            {
                i = 0;
                while (((i <= this._SafeStr_221) && (i < this._SafeStr_214.length)))
                {
                    seg = this._SafeStr_214[i];
                    this._SafeStr_206(seg, i, prevX, prevY);
                    prevX = seg.x;
                    prevY = seg.y;
                    i++;
                };
                i = (this._SafeStr_221 + 1);
                while (i < this._SafeStr_214.length)
                {
                    seg = this._SafeStr_214[i];
                    this._SafeStr_206(this._SafeStr_214[i], ((this._SafeStr_214.length - i) - 1), prevX, prevY, true);
                    prevX = seg.x;
                    prevY = seg.y;
                    i++;
                };
            };
        }

        public function setSplitLink(link:Link):void
        {
            this._SafeStr_198 = link;
            if (link != null)
            {
                link._SafeStr_198 = this;
                this._SafeStr_225(link._SafeStr_232());
            }
            else
            {
                this._SafeStr_197 = false;
                this._SafeStr_226.removeListener(this._SafeStr_194);
                this._SafeStr_226 = this._SafeStr_204;
                this._SafeStr_226.addListener(this._SafeStr_194);
                this._SafeStr_217 = null;
                this._SafeStr_194(this._SafeStr_226);
            };
        }

        public function addSeg():Boolean
        {
            return (this._SafeStr_231());
        }

        public function isAttached():Boolean
        {
            return (this._SafeStr_197);
        }

        public function sendAttack(amount:int):Boolean
        {
            var seg:LinkSegment = this._SafeStr_214[0];
            if (!seg)
            {
                return (false);
            };
            if (this._SafeStr_196)
            {
                seg.baseColor = this._SafeStr_196.baseColor();
            };
            if (((this._SafeStr_218) && (this._SafeStr_197)))
            {
                seg.setLoad(amount);
                return (true);
            };
            return (false);
        }

        public function getOrigAnchor():Anchor
        {
            return (this._SafeStr_213);
        }

        public function pause(enabled:Boolean):void
        {
            if (this._SafeStr_97 == enabled)
            {
                return;
            };
            this._SafeStr_97 = enabled;
            if (this._SafeStr_97)
            {
                removeEventListener(Event.ENTER_FRAME, this.onEnterFrame);
            }
            else
            {
                addEventListener(Event.ENTER_FRAME, this.onEnterFrame);
            };
        }


    }
}//package 

// _SafeStr_114 = "_-2u" (String#4791, DoABC#2)
// _SafeStr_122 = "_-W" (String#5281, DoABC#2)
// _SafeStr_123 = "_-Cg" (String#5258, DoABC#2)
// _SafeStr_124 = "_-4b" (String#4867, DoABC#2)
// _SafeStr_125 = "_-9a" (String#5106, DoABC#2)
// _SafeStr_194 = "_-2b" (String#4778, DoABC#2)
// _SafeStr_195 = "_-7e" (String#5015, DoABC#2)
// _SafeStr_196 = "_-7g" (String#5017, DoABC#2)
// _SafeStr_197 = "_-2S" (String#4772, DoABC#2)
// _SafeStr_198 = "_-4g" (String#4872, DoABC#2)
// _SafeStr_199 = "_-0x" (String#4698, DoABC#2)
// _SafeStr_200 = "_-Bk" (String#5212, DoABC#2)
// _SafeStr_201 = "_-9h" (String#5113, DoABC#2)
// _SafeStr_202 = "_-36" (String#4801, DoABC#2)
// _SafeStr_203 = "_-5a" (String#4915, DoABC#2)
// _SafeStr_204 = "_-2a" (String#4777, DoABC#2)
// _SafeStr_205 = "_-65" (String#4940, DoABC#2)
// _SafeStr_206 = "_-6Y" (String#4963, DoABC#2)
// _SafeStr_207 = "_-Ci" (String#5259, DoABC#2)
// _SafeStr_208 = " get" (String#3395, DoABC#2)
// _SafeStr_209 = "_-C2" (String#5229, DoABC#2)
// _SafeStr_210 = "_-B3" (String#5186, DoABC#2)
// _SafeStr_211 = "_-9z" (String#5127, DoABC#2)
// _SafeStr_212 = "_-6o" (String#4976, DoABC#2)
// _SafeStr_213 = "_-8I" (String#5046, DoABC#2)
// _SafeStr_214 = "_-8A" (String#5043, DoABC#2)
// _SafeStr_215 = "_-2-" (String#4749, DoABC#2)
// _SafeStr_216 = "_-v" (String#5300, DoABC#2)
// _SafeStr_217 = "_-2Q" (String#4770, DoABC#2)
// _SafeStr_218 = "_-4e" (String#4870, DoABC#2)
// _SafeStr_219 = "_-64" (String#4939, DoABC#2)
// _SafeStr_220 = "_-1p" (String#4739, DoABC#2)
// _SafeStr_221 = "_-4N" (String#4859, DoABC#2)
// _SafeStr_222 = "_-2v" (String#4792, DoABC#2)
// _SafeStr_223 = "_-0b" (String#4680, DoABC#2)
// _SafeStr_224 = "_-1r" (String#4741, DoABC#2)
// _SafeStr_225 = "_-1Q" (String#4721, DoABC#2)
// _SafeStr_226 = "_-9k" (String#5115, DoABC#2)
// _SafeStr_227 = "_-2Z" (String#4776, DoABC#2)
// _SafeStr_228 = "_-6O" (String#4956, DoABC#2)
// _SafeStr_229 = "_-6T" (String#4960, DoABC#2)
// _SafeStr_230 = "_-3k" (String#4829, DoABC#2)
// _SafeStr_231 = "_-80" (String#5035, DoABC#2)
// _SafeStr_232 = "_-Bq" (String#5217, DoABC#2)
// _SafeStr_233 = "_-7l" (String#5021, DoABC#2)
// _SafeStr_93 = "_-1j" (String#4736, DoABC#2)
// _SafeStr_97 = "_-1I" (String#4713, DoABC#2)


